<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="商品名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="goodsName">
              <a-input v-model="model.goodsName" placeholder="请输入商品名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="拼音码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pinyinCode">
              <a-input v-model="model.pinyinCode" placeholder="请输入拼音码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="goodsNumber">
              <a-input v-model="model.goodsNumber" placeholder="请输入商品编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="产地" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productionAddress">
              <a-input v-model="model.productionAddress" placeholder="请输入产地"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品性质id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="goodsNatureId">
              <a-input v-model="model.goodsNatureId" placeholder="请输入商品性质id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品性质名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="goodsNatureName">
              <a-input v-model="model.goodsNatureName" placeholder="请输入商品性质名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品类别id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xghGoodsTypeId">
              <a-input v-model="model.xghGoodsTypeId" placeholder="请输入商品类别id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品类别名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xghGoodsTypeName">
              <a-input v-model="model.xghGoodsTypeName" placeholder="请输入商品类别名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="成本核算id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="costCalculationId">
              <a-input v-model="model.costCalculationId" placeholder="请输入成本核算id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="成本核算名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="costCalculationName">
              <a-input v-model="model.costCalculationName" placeholder="请输入成本核算名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="条形码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="barCode">
              <a-input v-model="model.barCode" placeholder="请输入条形码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="规格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="specs">
              <a-input v-model="model.specs" placeholder="请输入规格"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="基本单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="baseUnit">
              <a-input v-model="model.baseUnit" placeholder="请输入基本单位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="默认单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="defaultUnit">
              <a-input v-model="model.defaultUnit" placeholder="请输入默认单位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="多单位状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="multiPriceStatus">
              <a-input v-model="model.multiPriceStatus" placeholder="请输入多单位状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="价格管理状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="priceStatus">
              <a-input v-model="model.priceStatus" placeholder="请输入价格管理状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="库存预警状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stockWarningStatus">
              <a-input v-model="model.stockWarningStatus" placeholder="请输入库存预警状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="期初库村状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stockStatus">
              <a-input v-model="model.stockStatus" placeholder="请输入期初库村状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="goodsRemark">
              <a-input v-model="model.goodsRemark" placeholder="请输入备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="禁用状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="disabledStatus">
              <a-input v-model="model.disabledStatus" placeholder="请输入禁用状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="删除状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deleteStatus">
              <a-input v-model="model.deleteStatus" placeholder="请输入删除状态"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'XghGoodsForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/goods/xghGoods/add",
          edit: "/goods/xghGoods/edit",
          queryById: "/goods/xghGoods/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$elMessage.success(res.message);
                that.$emit('ok');
              }else{
                that.$elMessage.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>